<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>消息1</button>
    <button>消息2</button>
    <button>群发</button>
    <script src="./socket.io.js"></script>
    <script>

        /* 
        io.emit("事件名",数据)
        io.on("事件名",callback)
        */
       var btns = document.querySelectorAll("button")
        var socket = io.connect('http://localhost:8081');
        btns[0].onclick = function(){
          
            socket.emit("msga",111);
        }
        btns[1].onclick = function(){
          
          socket.emit("msgb",222);
      }
       btns[2].onclick = function(){
           socket.emit("qunfa",'这是群发的消息')
       }
       socket.on("qunfa",(msg)=>{
        alert(msg)
       })
        socket.on('message', function(msg){
            console.log(msg)
          })
    </script>
</body>
</html>